package com.tiny.work.tiny_task;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
    private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
    public static void main(String []args) {
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        try {
            Scheduler scheduler = schedulerFactory.getScheduler();
            //创建一个JobDetJobDetail jobDetail = newJob(QuartzTest.class)
            JobDetail jobDetail = newJob(EmailJob.class)
                    .withIdentity("job1", "group1")
                    .build();
            //创建一个每周触发的Trigger,指明星期几几点几分
            Trigger trigger = newTrigger()
                    .withIdentity("cron")
                    .withSchedule(CronScheduleBuilder.cronSchedule("0/3 0/1 * 1/1 * ? *"))
                    .startNow()
                    .build();
            scheduler.scheduleJob(jobDetail, trigger);
            scheduler.start();
        } catch (SchedulerException e) {
            LOGGER.error("", e);
        }
    }
}
